﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Microsoft.Office.OneNote
{
    internal static class ExtensionICustomAttributeProvider
    {
        //public static IEnumerable<T> GetAttributes<T>(this ICustomAttributeProvider provider)
        //    where T : Attribute
        //{
        //    return GetAttributes<T>(provider, false);
        //}

        public static IEnumerable<T> GetAttributes<T>(this ICustomAttributeProvider provider, bool inherit)
            where T : Attribute
        {
            return provider.GetCustomAttributes(typeof(T), inherit).OfType<T>();
        }

        public static T GetAttribute<T>(this ICustomAttributeProvider provider, bool inherit)
            where T : Attribute
        {
            return GetAttributes<T>(provider, inherit).FirstOrDefault();
        }

        public static T GetAttribute<T>(this ICustomAttributeProvider provider)
            where T : Attribute
        {
            return GetAttribute<T>(provider, false);
        }
    }
}
